package emulator.shell.GUI.viewmodel;

import javax.swing.table.AbstractTableModel;

@SuppressWarnings("serial")
public class RegisterTableModel extends AbstractTableModel
{
	private static String[] columnNames = {
    		"Reg.",
            "#",
            "Value"
           	};
	
	private static int[] columnWidths = {
			40,
			20,
			40
	};
	
	private String [] rowNames = {
			"ORB", "ORA", "DDRB", "DDRA", 
			"T1CL", "T1CH", "T1LL", "T1LH",
			"T2CL", "T2CH", "SR", "ACR",
			"PCR", "IFR", "IER", "ORA2"
	};
	private Integer [] rowValues = new Integer [16];
	
	public RegisterTableModel()
	{
		for (int i = 0; i < rowValues.length; i++)
			rowValues[i] = new Integer(0);
	}

	@Override
	public int getRowCount()
	{
		return rowNames.length;
	}

	@Override
	public int getColumnCount()
	{
		return columnNames.length;
	}

	@Override
	public String getColumnName(int column)
	{
		return columnNames[column];
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex)
	{
		switch (columnIndex)
		{
		case 0: return rowNames[rowIndex];
		case 1: return rowIndex; 
		case 2: return rowValues[rowIndex];
		}
		return null;
	}

	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex)
	{
		return columnIndex == 2;
	}
	
	@Override
	public Class<?> getColumnClass(int columnIndex)
	{
		return getValueAt(0, columnIndex).getClass();
	}

	@Override
	public void setValueAt(Object aValue, int rowIndex, int columnIndex)
	{
		if (columnIndex == 2)
			rowValues[rowIndex] = (Integer)aValue;
	}

	public void setRegisterValue(int index, int value)
	{
		rowValues[index] = value;
	}

	public int getRegisterValue(int index)
	{
		return rowValues[index];
	}
	
	public int getColumnWidth(int columnIndex)
	{
		return columnWidths[columnIndex];
	}

}
